var util = require('../../utils/util.js');
var ajax = require('../../utils/ajax.js');
var common = require('../../utils/common.js');
var WxParse = require('../../utils/wxParse/wxParse.js');
var MPage = require('../MPage.js');
var app = getApp();

Page(common.extendPage(MPage, {

    /**
     * 页面的初始数据
     */
    data: {
        winHei: 0,
        cardList: [],
        userCard: [],
        haveCard: false,
        dataLoaded: false
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onShow: function(options) {
        this.getMembership();
    },
    getMembership: function() {
        var _self = this;
        ajax.P('/openapi/CUser/userCard', {},
            function(data) {

                var data = data.result;
                if (data.userCard) {
                    data.userCard.forEach(function(item, index) {
                        var cid = _self.PrefixInteger(item['cid'], 6);
                        item['cid'] = cid;
                    })
                }
                _self.setData({
                    winHei: app.getWinHei(),
                    cardList: data.cardList,
                    userCard: data.userCard,
                    haveCard: data.haveCard,
                    dataLoaded: true
                })
            })
    },
    selectedMembership: function() {
        var cardList = this.data.cardList;
        cardList.forEach(function(item) {

        })
    },
    PrefixInteger: function(num, length) {
        return (Array(length).join('0') + num).slice(-length);
    },
    _jump:function(evt){
        common.jump(evt);
    }
}))